home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: destroyNode.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:32 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include <stdio.h>
- #include "ess.h"
- #include "checking.h"
- #include "io.h"
- #include "object.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "bf_external_group.h"
- #include "version_graph.h"
- #include "version_funcs.h"
- #include "sm_macro.h"
-
- /*
- * DestroyNode() records the fact that a version has been destroyed.
- * This may involve leaving a tombstone in its place.
- */
-
- int
- destroyNode(
- VERSIONGRAPH *graph, /* graph containing node */
- VHGNODEID nodeId, /* node to destroy */
- BOOL *graphEmpty /* OUT: true if last node deleted */
- )
- {
- VHGNODE* node;
- VHGNODE* childNode;
-
- TRPRINT(TR_VERSION, TR_LEVEL_1, ("freezing node &d \n", nodeId) );
-
- CHECK_VERSIONGRAPH_MAGIC(graph);
-
- /*
- * So far the graph is not empty
- */
- *graphEmpty = FALSE;
-
- /*
- * Validate nodeId
- */
- if (nodeId >= graph->nodeCount) {
- SM_ERROR(TYPE_WARNING, esmINTERNAL);
- return(esmFAILURE);
- }
-
- /*
- * Get a pointer to the node
- */
- node = &graph->nodeArray[nodeId];
-
- /*
- * Do some defensive error checking.
- */
- CHECK_VHGNODE_MAGIC(node);
-
- /*
- * The Algorithm:
- * 1. If node has no children, remove it from the VHG and call
- * destroyNode on the parent(node) if the parent is a tombstone.
- * 2. If node has 1 child, delete the node and put the child
- * in it's place.
- * 3. if the node has > 1 children, make the node a tombstone
- */
-
- /*
- * See if node has no children
- */
- if (VHGLIST_EMPTY(graph, &node->children)) {
-
- /*
- * See if graph will now be empty, if so return that fact.
- */
- if (nodeId == graph->root) {
- *graphEmpty = TRUE;
- return (esmNOERROR);
- }
-
- /*
- * Remove the node, and put it on the free list
- */
- listVHGRemove(graph, &node->siblings);
- listVHGEnq(graph, &graph->freeList, &node->siblings);
-
- /*
- * If the parent is a tombstone, call destroy node on it
- */
- if (graph->nodeArray[node->parentId].flags & V_tombstone) {
- return(destroyNode(graph, node->parentId, graphEmpty));
- }
-
- } else if ( VHGDEREF(graph, node->children.succ)->succ ==
- VHGOFFSET(graph, &node->children) ) {
- /*
- * Node has only one child, so get it
- */
- childNode = listVHGDeq(graph, &node->children);
- CHECK_VHGNODE_MAGIC(childNode);
- SM_ASSERT(LEVEL_3, VHGLIST_EMPTY(graph, &node->children));
-
- /*
- * See if the node is the root node
- */
- if (node->parentId == VHGNULLNODE) {
-
- /*
- * Node is the root, so move the child into
- * the root position and place the node on the
- * free list.
- */
- SM_ASSERT(LEVEL_3, graph->root == nodeId);
- graph->root = childNode->id;
- childNode->parentId = VHGNULLNODE;
- listVHGEnq(graph, &graph->freeList, &node->siblings);
-
- } else {
-
- /*
- * Node is not the root node.
- * Place the child node on the list of siblings of node
- * and update its parent id.
- */
- listVHGEnq(graph, &node->children, &childNode->siblings);
- childNode->parentId = node->parentId;
-
- /*
- * Remove the orginal node, and put it on the free list
- */
- listVHGRemove(graph, &node->siblings);
- listVHGEnq(graph, &graph->freeList, &node->siblings);
- }
-
- } else {
-
- /*
- * Node has more than one child, so make it a tombstone
- */
- node->flags |= V_tombstone;
- }
- return(esmNOERROR);
- }
-